<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<h1>登录页</h1>
		<div>
			UserName:<input type="text" id="stname" name="stname" /><br/>
			PassWord:<input type="password" id="pwd" name="stpass" /><br/>
			<button>Login</button>
		</div>
	</body>
	<script>
		$(function(){
			$("button").click(function(){
				var name=$("#stname").val();
				var pwd=$("#pwd").val();
				//向后台发ajax请求
				var url="http://localhost:8080/login";	//绝对路径
				var data={
					"stname":name,
					"stpass":pwd
				};
				$.post(url,data,function(json){
					console.log(json)
					//json	服务器返回值
					//true 去主页  false提示
					if(json.success==true){
						alert(json.message)
						//存token
						localStorage.setItem("mstoken",json.data);
						$(".app").load("main.html")
						$("a").eq(0).text("退出登录")
					}else{
						alert(json.message)
					}
				
				})
			});
		});
	</script>
</html>
